package com.bie.action;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.util.ServletContextAware;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.woke.bean.CustomerBean;
import com.woke.bean.UserBean;
import com.woke.dao.Customer;
import com.woke.dao.User;

public class CustomerAction implements Action, ServletRequestAware, ServletResponseAware, ServletContextAware {
	private HttpServletRequest request;
	private HttpServletResponse responese;
	private HttpSession session;
	private ServletContext application;
	private String username;
	private String password;
	private User u;
	private String id;
	private String msg;
	private String role;
	private String tel;
	private String isprize;
	private String cusname;
	private String belongId;
	
	
	public String getBelongId() {
		return belongId;
	}

	public void setBelongId(String belongId) {
		this.belongId = belongId;
	}

	public String getCusname() {
		return cusname;
	}

	public void setCusname(String cusname) {
		this.cusname = cusname;
	}

	public String getIsprize() {
		return isprize;
	}

	public void setIsprize(String isprize) {
		this.isprize = isprize;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public HttpSession getSession() {
		return session;
	}

	public void setSession(HttpSession session) {
		this.session = session;
	}

	public User getU() {
		return u;
	}

	public void setU(User u) {
		this.u = u;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	
	public String execute() throws Exception {

		return null;
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;

	}

	public void setServletResponse(HttpServletResponse response) {
		this.responese = response;

	}

	public void setServletContext(ServletContext application) {
		this.application = application;

	}
	
	
public String getprize1() throws Exception {
		
		List<Customer> list = new ArrayList<Customer>();
		CustomerBean bm = new CustomerBean();
		String sql="select * from customer";
		list = bm.getCustomerList(sql);
		ActionContext.getContext().put("Customerlist", list);
		return "isprize";
	}
	
	
	public String getprize() throws Exception {
		
		List<Customer> list = new ArrayList<Customer>();
		CustomerBean bm = new CustomerBean();
		if(msg.equals("yes")) {
		String sql="select * from customer where isprize=yes";
		list = bm.getCustomerList(sql);
		ActionContext.getContext().put("Customerlist", list);
		return "isprize";
		}else {
			String sql="select * from customer where isprize=no";
			list = bm.getCustomerList(sql);
			ActionContext.getContext().put("Customerlist", list);
			return "isprize";
		}
	}
	
	public String getindex() throws Exception {
		String sql1="select * from user";
		List<User> list1=User.getData(sql1);
			int num=list1.size();
			ActionContext actionContext = ActionContext.getContext();
			Map session = actionContext.getSession(); 
			request.getSession().setAttribute("num", num);
			return "index1";
		} 
	
	public String updateCusId() throws Exception {
		CustomerBean bm = new CustomerBean();
		System.out.println("删除编号："+id);
		bm.updateCusid(id, "0");
		return "member-list";
	}
	
	public String updateC() throws Exception {
		CustomerBean bm = new CustomerBean();
		bm.updateCusid(id, "1");
		return "member-del";
	}
	
	public String updateCus() throws Exception {
		CustomerBean bm = new CustomerBean();
		bm.updateCustomer(id,belongId, cusname,isprize);
		return "member-list";
	}
	
	public String addCus() throws Exception {
		CustomerBean bm = new CustomerBean();
		cusname= new String(cusname.getBytes("ISO-8859-1"),"utf-8");
		System.out.println("添加客户 :"+cusname);
		bm.addcustomer(belongId,cusname,isprize);
		return "member-list";
	}
	
	public String deleCus() throws Exception {
		CustomerBean bm = new CustomerBean();
		bm.deleteCus(id);
		return "member-del";
	}
	
	
}
